﻿
using AuthTemplate.DTO.User;
using AuthTemplate.Infrastructure;
using AuthTemplate.Infrastructure.Token;
using AuthTemplate.MVC.Filter;
using AuthTemplate.Service;
using AuthTemplate.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AuthTemplate.MVC.Controllers
{
    
    [RoutePrefix("login")]
    public class LoginController: BaseController
    {
        private readonly IUserService userService;

        public LoginController(IUserService userService)
        {
            this.userService = userService;
        }

        [HttpPost]
        [Route("index")]
        public string Index(LoginInput input)
        {
            MyResponse<LoginOutput> output = new MyResponse<LoginOutput>();
            try
            {
                LoginOutput data = userService.Login(input);

                if(data != null)
                {
                    output.data = data;
                }
                else
                {
                    throw new Exception("用户名或密码错误");
                }
            }
            catch(Exception ex)
            {
                output.Code = 500;
                output.Message = ex.Message;
            }

            return JsonHelper.Serialize(output);
        }



    }
}